package Exercise01;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * spring控制反转IOC 与依赖注入DI的练手
 * 要求：
 * 1、新建一个老师Teacher类，有属性String name,char sex,int age
 * 有构造方法与get/set方法  toString()
 * 2、新建接口TeacherDao,里面有一个getTeacher()方法,返回老师对象
 * 3、新建接口实现TeacherDaoI类，实现接口TeacherDao,属性Teacher
 * 有set方法，及重写方法，返回Teacher
 * 4、新建接口TeacherService,里面有一个getTeacher()方法,返回老师对象
 * 5、新建接口实现TeacherServiceI类，实现接口TeacherDao,属性TeacherDao
 * 有set方法，及重写方法，返回Teacher
 * 6、新建类TeacherController,属性TeacherService,有set方法，
 * 还有getTeacher(),返回Teacher.
 * 7、测试类Exercise01，新建一个exercise01.xml的spring配置文件，把
 * 类进行bean管理，实现注入，输出Teacher
 */
public class Exercise01 {
    public static void main(String[] args) {
        //加载spring的配置文件
        ApplicationContext ac = new ClassPathXmlApplicationContext("exercise01.xml");
        //获取controller
        TeacherController tc = (TeacherController)ac.getBean("tc");
        //方法调用
        Teacher t = tc.getTeacher();
        System.out.println(t);
        int nums[] = t.getNums();
        System.out.println("\n数组的输出:");
        for(int i=0;i<nums.length;i++){
            System.out.print(nums[i]+"\t");
        }
        List<String> list = t.getList();
        System.out.println("\n集合List的输出：");
        for(int i=0;i<list.size();i++){
            System.out.print(list.get(i)+"\t");
        }
        Set<Double> set = t.getSet();
        System.out.println("\n集合Set的输出：");
        for (double d:set) {
            System.out.print(d+"\t");
        }
        Map<String,String> map = t.getMap();
        System.out.println("\n集合map的输出:");
        for (String key:map.keySet()) {
            String value = map.get(key);
            System.out.println("key="+key+",value="+value+"\t");
        }
        Properties pro = t.getPro();
        System.out.println("\n属性类的输出:");
        for (Object key: pro.keySet() ) {
            String name = key.toString();
            String value = pro.getProperty(name);
            System.out.println("name="+name+",value="+value);
        }
    }
}
